/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdMetadataBusinessSceneDefinitionBo;
import com.comac.ins.isfd.domain.vo.IsfdMetadataBusinessSceneDefinitionVo;
import com.comac.ins.isfd.service.IIsfdMetadataBusinessSceneDefinitionService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;

/**
 * 元数据管理-业务场景定义
 *
 * @author Lion Li
 * @date 2024-09-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/metadataBusinessSceneDefinition")
public class IsfdMetadataBusinessSceneDefinitionController extends BaseController {

    @Autowired
    private IIsfdMetadataBusinessSceneDefinitionService isfdMetadataBusinessSceneDefinitionService;

    /**
     * 查询元数据管理-业务场景定义列表
     */
    @SaCheckPermission("isfd:metadataBusinessSceneDefinition:list")
    @GetMapping("/list")
    public TableDataInfo<IsfdMetadataBusinessSceneDefinitionVo> list(IsfdMetadataBusinessSceneDefinitionBo bo, PageQuery pageQuery) {
        return isfdMetadataBusinessSceneDefinitionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出元数据管理-业务场景定义列表
     */
    @SaCheckPermission("isfd:metadataBusinessSceneDefinition:export")
    @Log(title = "元数据管理-业务场景定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdMetadataBusinessSceneDefinitionBo bo, HttpServletResponse response) {
        List<IsfdMetadataBusinessSceneDefinitionVo> list = isfdMetadataBusinessSceneDefinitionService.queryList(bo);
        ExcelUtil.exportExcel(list, "元数据管理-业务场景定义", IsfdMetadataBusinessSceneDefinitionVo.class, response);
    }

    /**
     * 获取元数据管理-业务场景定义详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:metadataBusinessSceneDefinition:query")
    @GetMapping("/{id}")
    public R<IsfdMetadataBusinessSceneDefinitionVo> getInfo(@NotNull(message = "主键不能为空")
                                                            @PathVariable Long id) {
        return R.ok(isfdMetadataBusinessSceneDefinitionService.queryById(id));
    }

    /**
     * 新增元数据管理-业务场景定义
     */
    @SaCheckPermission("isfd:metadataBusinessSceneDefinition:add")
    @Log(title = "元数据管理-业务场景定义", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdMetadataBusinessSceneDefinitionBo bo) {
        return toAjax(isfdMetadataBusinessSceneDefinitionService.insertByBo(bo, 0L, 0L));
    }

    /**
     * 修改元数据管理-业务场景定义
     */
    @SaCheckPermission("isfd:metadataBusinessSceneDefinition:edit")
    @Log(title = "元数据管理-业务场景定义", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdMetadataBusinessSceneDefinitionBo bo) {
        return toAjax(isfdMetadataBusinessSceneDefinitionService.updateByBo(bo));
    }

    /**
     * 删除元数据管理-业务场景定义
     *
     * @param id 主键串
     */
    @SaCheckPermission("isfd:metadataBusinessSceneDefinition:remove")
    @Log(title = "元数据管理-业务场景定义", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(isfdMetadataBusinessSceneDefinitionService.deleteWithValidById(id, true));
    }
}
